﻿using System;
using System.Data;
using System.Configuration;
using System.Web;

using PKURG.CostSplit.Common;
using System.Threading;
using System.Diagnostics;

/// <summary>
/// Global 的摘要说明
/// </summary>
public class Global : HttpApplication
{
    string className = "Global";
    public Global()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    private bool IsExecute = false;
    void Application_Start(object sender, EventArgs e)
    {

    }


    private void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
    {

    }


    void Application_End(object sender, EventArgs e)
    {
        //  在应用程序关闭时运行的代码
    }

    #region 捕获错误信息，发送错误提醒邮件

    void Application_Error(object sender, EventArgs e)
    {
        // 在出现未处理的错误时运行的代码
        Exception objErr = Server.GetLastError().GetBaseException();

        string sError = "RecordBy:Star\r\n发生异常页: " + HttpContext.Current.Request.Url.ToString() + "\r\n";
        sError += "异常信息: " + objErr.Message + "\r\n";
        if (HttpContext.Current.Request.LogonUserIdentity != null)
        {
            sError += "用户: " + HttpContext.Current.Request.LogonUserIdentity.Name + "\r\n";
        }

        sError += "异常跟踪: " + objErr.StackTrace + "\r\n";
        //清除前一个异常
        Server.ClearError();
        //此处理用Session["ProError"]出错。所以用 Application["ProError"]
        Application["ProError"] = objErr;// sError;
        //string sPath = HttpContext.Current.Request.ApplicationPath;
        //此处是不是page中，不能用Response.Redirect("../frmSysError.aspx");

        EventLog.WriteEntry("CostSplit", sError, EventLogEntryType.Warning);

        System.Web.HttpContext.Current.Server.Transfer("~/error.aspx");
    }



    #endregion

    void Session_Start(object sender, EventArgs e)
    {


    }

    void Session_End(object sender, EventArgs e)
    {

    }
}
